/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.reportlose.service
 * FILE    NAME: ReportLoseDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.api.reportlose.service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson.JSON;
import com.hero.common.web.excel.util.ExcelExport;
import com.hero.core.constant.SysConstant;
import com.hero.core.entity.PageResult;
import com.hero.core.entity.ResponseEntity;
import com.hero.core.exception.AbstractGenericException;
import com.hero.core.util.DateUtils;
import com.hero.core.util.StringUtils;
import com.hero.core.util.ValidationUtil;
import com.jodinfo.outmirror.api.dictionary.util.DictionaryUtil;
import com.jodinfo.outmirror.api.loseform.entity.LoseformEntity;
import com.jodinfo.outmirror.api.loseform.service.LoseformQueryService;
import com.jodinfo.outmirror.api.org.entity.OrgEntity;
import com.jodinfo.outmirror.api.org.service.OrgQueryService;
import com.jodinfo.outmirror.api.purbarcode.entity.PurBarcodeEntity;
import com.jodinfo.outmirror.api.purbarcode.service.PurBarcodeQueryService;
import com.jodinfo.outmirror.api.reportinventoryanalyze.service.OfficeEntity;
import com.jodinfo.outmirror.api.reportlose.entity.ReportLoseEntity;
import com.jodinfo.outmirror.api.reportlosebarcode.entity.ReportLoseBarcodeEntity;
import com.jodinfo.outmirror.api.workflow.service.ActivitiTaskQueryService;
import com.taobao.ad.easyschedule.dataobject.JobData;
import com.taobao.ad.easyschedule.dataobject.JobResult;

@Service(value="reportLoseBizService")
public class ReportLoseBizServiceImpl implements ReportLoseBizService {
    private static final Logger logger = LoggerFactory.getLogger(ReportLoseBizServiceImpl.class);
 	
 	@Resource(name="reportLoseDmlService")
	private ReportLoseDmlService ReportLoseDmlService;
	@Resource(name="reportLoseQueryService")
	private ReportLoseQueryService ReportLoseQueryService;
	@Resource(name="reportLoseTransactionService")
	private ReportLoseTransactionService reportLoseTransactionService;
	@Resource(name="activitiTaskQueryService")
	private ActivitiTaskQueryService activitiTaskQueryService;
	@Resource(name="orgQueryService")
	private OrgQueryService orgQueryService;
	@Resource(name="loseformQueryService")
	private LoseformQueryService loseformQueryService;
	@Resource(name="purBarcodeQueryService")
	private PurBarcodeQueryService purBarcodeQueryService;
	
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportlose.ReportLoseBizService#addReportLose(ReportLoseEntity ReportLoseEntity)
	 * @param ReportLoseEntity ReportLoseEntity
	 * @return int
	 */
	public ResponseEntity addReportLose(ReportLoseEntity ReportLoseEntity) {
			ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
			  	 int i =  ReportLoseDmlService.addReportLose(ReportLoseEntity);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportlose.ReportLoseBizService#updateReportLose(ReportLoseEntity ReportLoseEntity)
	 * @param ReportLoseEntity ReportLoseEntity
	 * @return ResponseEntity
	 */
	public ResponseEntity updateReportLose(ReportLoseEntity ReportLoseEntity) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
				int i = ReportLoseDmlService.updateReportLose(ReportLoseEntity);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportlose.ReportLoseBizService#queryAllReportLose(ReportLoseEntity ReportLoseEntity)
	 * @param ReportLoseEntity ReportLoseEntity
	 * @return String
	 */
	public String queryAllReportLose(ReportLoseEntity ReportLoseEntity) {
		return JSON.toJSONString(ReportLoseQueryService.queryAllReportLose(ReportLoseEntity));
	} 
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportlose.ReportLoseBizService#queryAllReportLose(ReportLoseEntity ReportLoseEntity)
	 * @param ReportLoseEntity ReportLoseEntity
	 * @return PageResult
	 */
	public String queryListForPageReportLose(ReportLoseEntity ReportLoseEntity) {
		List<ReportLoseEntity> list = ReportLoseQueryService.queryListForPageReportLose(ReportLoseEntity);
		convertCodeToName(list);
		return new PageResult(list , ReportLoseQueryService.queryCountReportLose(ReportLoseEntity)).toString();
	} 
	/**
	 * 数据字典转换
	 * @author cao.weiwei
	 * @date 2017年7月18日 下午4:53:42
	 * @param list
	 */
	private void convertCodeToName(List<ReportLoseEntity> list) {
		 if(!CollectionUtils.isEmpty(list)){
			 for(ReportLoseEntity entity: list){
				 entity.setStatus(DictionaryUtil.conversionKeyToValue("78", entity.getStatus()));
				 entity.setType(DictionaryUtil.conversionKeyToValue("76", entity.getType()));
			 }
		 }
	}
	/** 
	 * 
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportlose.ReportLoseQueryService#queryById(ReportLoseEntity ReportLoseEntity)
	 * @param BigInteger id
	 * @return
	 */
	public ReportLoseEntity queryById(BigInteger id) {
		return ReportLoseQueryService.queryById(id);
	}
	
	public void exportReportLose(ReportLoseEntity ReportLoseEntity, HttpServletResponse response) {
		List<ReportLoseEntity> exportList = null;
		String ids = ReportLoseEntity.getIds();
		if (ValidationUtil.isNullOrEmptyString(ids)) {
			exportList =ReportLoseQueryService.queryAllReportLose(ReportLoseEntity);
		} else {
			String[] idArray = ids.split(",");
			List<BigInteger> idList = new ArrayList<BigInteger>();
			for(String id : idArray) {
				idList.add(new BigInteger(id));
			}
			exportList = ReportLoseQueryService.queryByIds(idList);
		}
		// 将字典中的code转换为name
		convertCodeToName(exportList);
		ExcelExport.exportExcel(exportList, "ReportLoseEntityExcel", "ReportLoseEntity信息", response);
	}
	
	/** 
	 * 批量删除 数据处理
	 * @author weiwei
	 * @date 2016年12月30日 上午9:15:36
	 * @see com.jodinfo.outmirror.implementation.reportlose.ReportLoseQueryService#queryById(ReportLoseEntity ReportLoseEntity)
	 * @param BigInteger id
	 * @return
	 */
	public ResponseEntity batchDelReportLose(ReportLoseEntity ReportLoseEntity) {
		String ids = ReportLoseEntity.getIds();
		String[] idArray = ids.split(",");
		List<ReportLoseEntity> ReportLoseEntityList = new ArrayList<ReportLoseEntity>();
		for(String id : idArray) {
			ReportLoseEntity ReportLoseModel = new ReportLoseEntity();
			ReportLoseModel.setId(new BigInteger(id));
//			ReportLoseModel.setLastUpdateUsrName(UserContext.getUser().getName());
//			ReportLoseModel.setLastUpdateTime(DateUtils.getCurrentTime());
//			ReportLoseModel.setIsDel(SysConstant.IS_DEL_Y);
			ReportLoseModel.setUpdateTime(DateUtils.getCurrentTime());
			ReportLoseEntityList.add(ReportLoseModel);
		}
		return batchUpdateReportLose(ReportLoseEntityList);
	}
	
	/**
	 * 执行批量删除操作
	 * @author weiwei
	 * @date 2017年3月13日 上午11:40:31
	 * @param ReportLoseList
	 * @return
	 */
	public ResponseEntity batchUpdateReportLose(List<ReportLoseEntity> ReportLoseList) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
			try{
				int i = ReportLoseDmlService.batchUpdateReportLose(ReportLoseList);
				 rs.setMessage(i+"条记录操作成功");
			 }catch(AbstractGenericException e){
				logger.error(e.getFullMessage());
				rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
			}catch(Exception e){
				String errorMessage = StringUtils.toString(e);
				logger.error(errorMessage);
				rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
			}
		return rs;
	}
	
	/**
	 * 
	 * @author weiwei
	 * @date 2017年3月13日 上午10:24:53
	 * @see  com.jodinfo.outmirror.implementation.reportlose.ReportLoseQueryService#queryById(ReportLoseEntity ReportLoseEntity)
	 * @param map
	 * @param excelimportcontext
	 * @param s
	 * @return
	 * @throws Exception
	 */
	/*public List<BigInteger> insertData(Map<Integer, List<Object>> map,ExcelImportContext excelimportcontext, String s) throws Exception {
		String usrName = UserContext.getUser().getName();//数据创建人
		String creatTime = DateUtils.getCurrentTime();
		List<ReportLoseEntity> ReportLoseList = validateReportLoseData(map, excelimportcontext,usrName,creatTime);
		if (!excelimportcontext.hasError() && ReportLoseList.size() > 0) {
			batchAddReportLose(ReportLoseList);
		}
		return null;
	}*/
	
	/**
	 * 
	 * TODO 验证数据 处理业务数据
	 * @author weiwei
	 * @date 2017年3月13日 上午9:33:30
	 * @see  com.jodinfo.outmirror.implementation.reportlose.ReportLoseQueryService#queryById(ReportLoseEntity ReportLoseEntity)
	 * @param ReportLoseList
	 * @return
	 */
	/*public List<ReportLoseEntity> validateReportLoseData(Map<Integer, List<Object>> map,ExcelImportContext excelimportcontext,String usrName,String creatTime) {
		ExcelImportContext.DataError errorMsg = null;
		List<ReportLoseEntity> ReportLoseList = new ArrayList<ReportLoseEntity>();
		for (Map.Entry<Integer, List<Object>> entity : map.entrySet()) {
			List<Object> excelModelList = entity.getValue();
			if (ValidationUtil.isNullOrEmptyCollection(excelModelList)) {
		//		errorMsg = excelimportcontext.new DataError(InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET,
		//				"导入数据为空！",InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET);
		//		excelimportcontext.push(errorMsg);
			}else{
				//TODO 验证对应数据
				for (int i =0;i<excelModelList.size();i++) {
					ReportLoseEntity ReportLoseModel = (ReportLoseEntity) excelModelList.get(i);
	 				if (checkDataByEntityModel(shShopModel, excelimportcontext, i)) {
						break;
					}
					//TODO 实体对象加入对应参数值 
					ReportLoseModel = setEntityData(ReportLoseModel,usrName, creatTime);
					ReportLoseList.add(ReportLoseModel);
				}
			}
		}
		return ReportLoseList;
	}*/
	
	/**
	 * 
	 * 单个导入实体数据校验 有错误返回true
	 * @author weiwei
	 * @date 2017年3月28日 下午3:59:17
	 * @param eqEquipmentModel
	 * @param excelimportcontext
	 * @param i
	 * @return
	 */
	/*public boolean checkDataByEntityModel(ReportLoseEntity ReportLoseModel,ExcelImportContext excelimportcontext,int i) {
		if (checkSingleData(excelimportcontext, ReportLoseModel.getIsDel, i+2,"错误信息") 
			//	|| checkSingleData(excelimportcontext, ReportLoseModel.getEquipmentColor(), i+2, "颜色为空！")
			//	||checkSingleData(excelimportcontext, ReportLoseModel.getEquipmentModel(), i+2, "型号为空！")
				) {
			return true;
		}else{
			return false;
		}
	}*/
	
	/**
	 * 
	 * 设置报错信息
	 * @author weiwei
	 * @date 2017年3月22日 下午5:17:37
	 * @param excelimportcontext
	 * @param rowNumId
	 * @param errorMessage
	 * @param sheetNumId 现在只有一个sheet 就不传值 默认值即可
	 */
	/*public boolean checkSingleData(ExcelImportContext excelimportcontext,String checkVal,int rowNumId,String errorMessage) {
		boolean flag = false;
		ExcelImportContext.DataError errorMsg = null;
		if (ValidationUtil.isNullOrEmptyString(checkVal)) {
			errorMsg = excelimportcontext.new DataError(rowNumId,errorMessage,InventoryConstantUtil.IMPORT_DATA_ERROR_TYPE_NOT_SHEET);
			excelimportcontext.push(errorMsg);
			flag = true;
		}
		return flag;
	}*/
	
	/**
	 * 
	 * 导入单个实体添加统一导入人及导入时间
	 * @author zhuxiaoliu
	 * @date 2017年3月28日 下午4:05:15
	 * @param eqEquipmentModel
	 * @param usrName
	 * @param creatTime
	 * @return
	 */
	/*public ReportLoseEntity setEntityData(ReportLoseEntity ReportLoseModel,String usrName,String creatTime) {
		
		//ReportLoseModel.setEquipmentId(InventoryConstantUtil.EQ_EQUIPMENT_SEQUENCE);
		ReportLoseModel.setCreateTime(creatTime);
		ReportLoseModel.setCreateUsrName(usrName);
		ReportLoseModel.setLastUpdateUsrName(usrName);
		ReportLoseModel.setLastUpdateTime(creatTime);
		ReportLoseModel.setIsDel(SysConstant.IS_DEL_N);
		return ReportLoseModel;
	}*/
	
	
	/**
	 * 
	 * 执行批插入操作
	 * @author weiwei
	 * @date 2017年3月13日 上午11:37:14
	 * @param {moduleName}List
	 * @return
	 */
	public ResponseEntity batchAddReportLose(List<ReportLoseEntity> ReportLoseList) {
		 ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS, "操作成功");
		try{
			int i = ReportLoseDmlService.batchAddReportLose(ReportLoseList);
			 rs.setMessage(i+"条记录插入操作成功");
		 }catch(AbstractGenericException e){
			logger.error(e.getFullMessage());
			rs.setStatus(SysConstant.FAIL).setMessage(e.getFullMessage());
		}catch(Exception e){
			String errorMessage = StringUtils.toString(e);
			logger.error(errorMessage);
			rs.setStatus(SysConstant.FAIL).setMessage(errorMessage);
		}
		return rs;
	}
	public JobResult execute(JobData jobData) throws Exception {
		ResponseEntity rs = scanFinishedForm(null);
		JobResult jobResult = JobResult.succcessResult();
		jobResult.setResultMsg(rs.getMessage());
		return jobResult;
	}
	/**
	 * 定时任务内容
	 * @author cao.weiwei
	 * @date 2017年7月14日 上午11:12:28
	 * @return
	 */
	public ResponseEntity scanFinishedForm(String date) {
		ResponseEntity rs = new ResponseEntity(SysConstant.SUCCESS,"操作成功");
		try{
			
		List<ReportLoseEntity> reportLoseEntityList = new ArrayList<ReportLoseEntity>();
		List<ReportLoseBarcodeEntity> reportLoseBarcodeEntityList = new ArrayList<ReportLoseBarcodeEntity>();
		List<LoseformEntity> list = null;
		if(StringUtils.isEmpty(date)){
			list = queryYesterDayForm();
		}else{
			list = queryOneDayForm(date);
		}
		
		if(!CollectionUtils.isEmpty(list)){
			for(LoseformEntity entity: list){
				PurBarcodeEntity purBarcodeEntity = new PurBarcodeEntity();
				purBarcodeEntity.setBusinessKey(entity.getWoNo());
				List<PurBarcodeEntity> purBarcodeEntityList = purBarcodeQueryService.queryGroupByEqId(purBarcodeEntity);
				buildReportLoseEntity(entity, purBarcodeEntityList,reportLoseEntityList);
				List<PurBarcodeEntity> purBarcodeEntityList2 = purBarcodeQueryService.queryAllPurBarcode(purBarcodeEntity);
				buildReportLoseBarcodeEntity(entity, purBarcodeEntityList2,reportLoseBarcodeEntityList);
			}
		}
		if(!StringUtils.isEmpty(date)){
			setUpdateTimeOneDay(date,reportLoseEntityList,reportLoseBarcodeEntityList);
		}else{
			setUpdateTime(reportLoseEntityList,reportLoseBarcodeEntityList);
		}
		reportLoseTransactionService.addReportLoseAndBarcode(reportLoseEntityList,reportLoseBarcodeEntityList);
		}catch(Exception e){
			logger.debug(StringUtils.toString(e));
			rs.setMessage(StringUtils.toString(e));
			rs.setStatus(SysConstant.FAIL);
		}
		return rs;
		
	}
	
	private void setUpdateTime(List<ReportLoseEntity> reportLoseEntityList,
			List<ReportLoseBarcodeEntity> reportLoseBarcodeEntityList) {
		String todayDate = DateUtils.getCurrentTime().substring(0,10);
		Date yesterD = DateUtils.getDatePlusDay(DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, todayDate), -1);
		String yester =  DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, yesterD);
		for(ReportLoseEntity r : reportLoseEntityList){
			r.setUpdateTime(yester);
		}
		for(ReportLoseBarcodeEntity r: reportLoseBarcodeEntityList){
			r.setUpdateTime(yester);
		}
	}
	/**
	 * 设置更新时间
	 * @author cao.weiwei
	 * @date 2017年8月9日 上午11:55:19
	 * @param date
	 * @param reportLoseEntityList
	 * @param reportLoseBarcodeEntityList
	 */
	private void setUpdateTimeOneDay(String date,
			List<ReportLoseEntity> reportLoseEntityList,
			List<ReportLoseBarcodeEntity> reportLoseBarcodeEntityList) {
		Date updateTime = DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, date);
		String updateTimeStr = DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, updateTime);
		for(ReportLoseEntity r : reportLoseEntityList){
			r.setUpdateTime(updateTimeStr);
		}
		for(ReportLoseBarcodeEntity r: reportLoseBarcodeEntityList){
			r.setUpdateTime(updateTimeStr);
		}
	}
	/**
	 * 查询昨日已完成的遗失单
	 * @author cao.weiwei
	 * @date 2017年7月14日 上午11:11:42
	 * @return
	 */
	private List<LoseformEntity> queryYesterDayForm() {
		LoseformEntity loseform = new LoseformEntity();
		Date todayDate = DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, DateUtils.getCurrentTime().substring(0, 10));
		Date yesterDate = DateUtils.getDatePlusDay(todayDate, -1);
		loseform.setPassTimeStart(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, yesterDate));
		loseform.setPassTimeEnd(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, todayDate));
		loseform.setStatus("3"); // 审批通过
		List<LoseformEntity> list = loseformQueryService.queryAllLoseform(loseform);
		return list;
	}
	/**
	 * 查询某日已完成的遗失单
	 * @author cao.weiwei
	 * @date 2017年8月9日 上午11:51:26
	 * @return
	 */
	private List<LoseformEntity> queryOneDayForm(String date) {
		LoseformEntity loseform = new LoseformEntity();
		Date theDate = DateUtils.stringToDate(DateUtils.TIMEPATTERN_YYYYMMDD, date);// 当天
		Date theDateAfter = DateUtils.getDatePlusDay(theDate, 1);
		loseform.setPassTimeStart(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, theDate));
		loseform.setPassTimeEnd(DateUtils.DateToString(DateUtils.TIMEPATTERN_YYYYMMDD, theDateAfter));
		loseform.setStatus("3"); // 审批通过
		List<LoseformEntity> list = loseformQueryService.queryAllLoseform(loseform);
		return list;
	}

	private OfficeEntity getOfficeEntity(String orgId,String orgName){
		OrgEntity orgEntity = new OrgEntity();
		orgEntity.setOrgId(orgId);
		OrgEntity org =  orgQueryService.queryByEntity(orgEntity);
		OfficeEntity ofe = new OfficeEntity();
		if(org!=null){
			if(org.getOrgId().equals(orgId)){
				if(org.getOrgType().equals("0")){
					ofe.setBranchOrgId(org.getOrgId());
					ofe.setBranchOrgName(org.getOrgName());
					ofe.setOfficeOrgId(org.getOrgId());
					ofe.setOfficeOrgName(org.getOrgName());
				}else if(org.getOrgType().equals("1")){
					ofe.setBranchOrgId(org.getOrgId());
					ofe.setBranchOrgName(org.getOrgName());
					ofe.setOfficeOrgId(org.getOrgId());
					ofe.setOfficeOrgName(org.getOrgName());
				}else if(org.getOrgType().equals("2")){
					ofe.setBranchOrgId(org.getParentOrgId());
					ofe.setBranchOrgName(org.getParentOrgName());
					ofe.setOfficeOrgId(org.getOrgId());
					ofe.setOfficeOrgName(org.getOrgName());
				}
			}
		}else{
			ofe.setBranchOrgId(orgId);
			ofe.setBranchOrgName(orgName);
			ofe.setOfficeOrgId(orgId);
			ofe.setOfficeOrgName(orgName);
		}
		
		return ofe;
	}
		private void buildReportLoseEntity(LoseformEntity losefomEntity, List<PurBarcodeEntity> purBarcodeEntityList,
				List<ReportLoseEntity> reportLoseEntityList) {
			OfficeEntity office =  getOfficeEntity(losefomEntity.getOrgId(), losefomEntity.getOrgName());
		
			if(!CollectionUtils.isEmpty(purBarcodeEntityList)){
				for(PurBarcodeEntity purBarcodeEntity : purBarcodeEntityList){
					ReportLoseEntity reportLoseEntity = new ReportLoseEntity();
					reportLoseEntity.setBusinessId(purBarcodeEntity.getBusinessKey());
					reportLoseEntity.setEquipmentId(purBarcodeEntity.getEquipmentId());
					reportLoseEntity.setEquipmentName(purBarcodeEntity.getEquipmentName());
					reportLoseEntity.setEquipmentTypeId(purBarcodeEntity.getEquipmentType());
					reportLoseEntity.setEquipmentTypeName(purBarcodeEntity.getEquipmentTypeName());
					reportLoseEntity.setQuantity(purBarcodeEntity.getQty());
					reportLoseEntity.setCreateUser(losefomEntity.getCreateUser());
					reportLoseEntity.setCreateUserId(losefomEntity.getCreateUserId());
					reportLoseEntity.setCreateDate(losefomEntity.getCreateTime());
					reportLoseEntity.setType(losefomEntity.getType());
					reportLoseEntity.setStatus(losefomEntity.getStatus());
					if("1".equals(losefomEntity.getType())){ // 店铺丢失
						reportLoseEntity.setShopId(losefomEntity.getShopId());
						reportLoseEntity.setShopName(losefomEntity.getShopName());
					}else if("2".equals(losefomEntity.getType())){ // 仓库丢失
						reportLoseEntity.setShopId(losefomEntity.getStorageId());
						reportLoseEntity.setShopName(losefomEntity.getStorageName());
					}
					reportLoseEntity.setReason(losefomEntity.getReason()); 
					reportLoseEntity.setBranchOrgId(office.getBranchOrgId());
					reportLoseEntity.setBranchOrgName(office.getBranchOrgName());
					reportLoseEntity.setOfficeOrgId(office.getOfficeOrgId());
					reportLoseEntity.setOfficeOrgName(office.getOfficeOrgName());
					reportLoseEntityList.add(reportLoseEntity);
				}
			}
		}
		
		private void buildReportLoseBarcodeEntity(LoseformEntity losefomEntity, List<PurBarcodeEntity> purBarcodeEntityList,
				List<ReportLoseBarcodeEntity> reportLoseBarcodeEntityList) {
			if(!CollectionUtils.isEmpty(purBarcodeEntityList)){
				for(PurBarcodeEntity purBarcodeEntity : purBarcodeEntityList){
					ReportLoseBarcodeEntity reportLoseBarcodeEntity = new ReportLoseBarcodeEntity();
					reportLoseBarcodeEntity.setBusinessId(purBarcodeEntity.getBusinessKey());
					reportLoseBarcodeEntity.setEquipmentTypeId(purBarcodeEntity.getEquipmentType());
					reportLoseBarcodeEntity.setEquipmentTypeName(purBarcodeEntity.getEquipmentTypeName());
					reportLoseBarcodeEntity.setEquipmentId(purBarcodeEntity.getEquipmentId());
					reportLoseBarcodeEntity.setEquipmentName(purBarcodeEntity.getEquipmentName());
					reportLoseBarcodeEntity.setEquipmentBarcode(purBarcodeEntity.getEquipmentBarcode());
					reportLoseBarcodeEntityList.add(reportLoseBarcodeEntity);
				}
			}
		}
		
		public ResponseEntity testTask(String date) {
			if(StringUtils.isEmpty(date)){
				return scanFinishedForm(null);
			}else{
				return scanFinishedForm(date);
			}
			
		}
}

